package p1290

import node.ListNode
import java.util.*

class StackStragty : Stragty {
    override fun getDecimalValue(head: ListNode?): Int {
        var tempt: ListNode? = head
        val stack: Stack<ListNode> = Stack()
        while (tempt != null) {
            stack.push(tempt)
            tempt = tempt.next
        }

        var sum: Double = 0.0
        var level: Int = 0
        while (!stack.empty()) {
            tempt = stack.pop()
            sum += tempt.`val` * Math.pow(2.0, level * 1.0)
            level++
        }
        return sum.toInt()
    }
}